package com.lily.ssm.model;

import java.util.List;

public class Pager<E> {
	private int totalPage;	//总页数
	private int pageSize=8;	//显示的页数	(设置默认值8)
	private int count;	//总记录数	
	private int pageIndex=1;	//当前页数(设置默认值1)
	private int offset;	//分页偏移量  	(limit offset,pageSize)
	private int start;	//分页显示开始数字
	private int end;	//分页显示结束数字
	private List<E> datas;	//查询记录数
	
	public int getTotalPage() {
		//总页数=总记录数/显示页数	向上转型，取整数
		totalPage = (int)Math.ceil((double)count/pageSize);
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	public int getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(int pageIndex) {
		/*if(pageIndex<=5){
			start=1;
			end = 5;
		}else if(pageIndex==totalPage){
			start = pageIndex-5;
			end = totalPage;
		}else if(pageIndex > 5){
			start = pageIndex - 2;
			end = pageIndex + 2 > getTotalPage()?getTotalPage():(pageIndex + 2);
		}*/
		if(pageIndex<=5){
			start=1;
			end = getTotalPage() > 5 ? 5 : getTotalPage();
		}else if(pageIndex > 5 && pageIndex<=getTotalPage()-5){
			start = pageIndex - 2;
			end = pageIndex + 2 ;
		}else if(pageIndex>getTotalPage()-5 && pageIndex<=getTotalPage()){
			start = totalPage-4;
			end = totalPage;
		}
		this.pageIndex = pageIndex;
	}
	public int getOffset() {
		//分页偏移量 = (当前页-1)*显示页数
		offset = (pageIndex-1)*pageSize ;
		return offset;
	}
	public void setOffset(int offset) {
		this.offset = offset;
	}
	public List<E> getDatas() {
		return datas;
	}
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getEnd() {
		return end;
	}
	public void setEnd(int end) {
		this.end = end;
	}
	public void setDatas(List<E> datas) {
		this.datas = datas;
	}
	 
}
